package com.zzf.rpc;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author zzf
 * @date 2018/8/13 13:42.
 */
public class RemoteInvocationHandler implements InvocationHandler {


    private String host;
    private int port;

    public RemoteInvocationHandler(String host, int port) {
        this.host = host;
        this.port = port;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        //组装请求
         RpcRequest request = new RpcRequest();
         request.setClassName(method.getDeclaringClass().getName());
         request.setMethodName(method.getName());
         request.setParameters(args);
        //进行tcp 传输
        TCPTransport tcpTransport = new TCPTransport(host, port);
        return tcpTransport.send(request);
    }
}
